package com.zmht.beike.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.zmht.beike.core.BaseAction;
import com.zmht.beike.po.StudentTwo;
import com.zmht.beike.po.THealthmovement;
import com.zmht.beike.util.TimeUtil;
import com.zmht.beike.web.form.HealthMovementForm;
import com.zmht.specedu.vo.Teacher;

public class HealthMovementAction extends BaseAction {
	/**
	 * 获得
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward getHealthMovement(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
			String studentId = request.getParameter("studentId");
			THealthmovement ht = null;
			if("edit".equals(request.getSession().getAttribute("action"))){
				ht = this.getHealthMovementBiz().findByStudentId(studentId);
			}
			request.setAttribute("healthmovement", ht);
			request.setAttribute("studentId", studentId);
		return new ActionForward("/jsp/pingce/ceping_healthmovement.jsp");
	}
	/**
	 * 更新
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward updateHealthMovement(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
			String studentId = request.getParameter("studentId");
			//THealthmovement ht = this.getHealthMovementBiz().findByStudentId(studentId);
			HealthMovementForm frm = (HealthMovementForm)form;
			THealthmovement ht = new THealthmovement();
			BeanUtils.copyProperties(ht, frm);
			ht.setCtime(TimeUtil.getYMDTime());
			if(new Integer(0).equals(ht.getId()))
				this.getHealthMovementBiz().saveHealthmovement(ht);
			else
				this.getHealthMovementBiz().updateHealthmovement(ht);
			
			
			//更新学生记录
			StudentTwo student = (StudentTwo)this.getStudentBiz().getStudentDAO().findById(StudentTwo.class, new Integer(studentId));
			student.setSumHealth(ht.getScore());
			student.setPingceDate(TimeUtil.getYMDTime());
			Teacher teacher = (Teacher)request.getSession().getAttribute("current_user_session_key");
			student.setWreteName(teacher.getTname());
			this.getStudentBiz().getStudentDAO().updateObj(student);
			request.setAttribute("studentId", studentId);
		return new ActionForward("/beike/healthMovement.do?method=getHealthMovement&studentId="+studentId);
	}
}
